const likeModel = require('../models/likeModel');
const { sendSuccess, sendError } = require('../utils/response');

module.exports = {
  // 点赞评论
  async likeReview(req, res) {
    try {
      const { id: userId } = req.user;
      const { review_id } = req.body;
      
      if (!review_id) {
        return sendError(res, '缺少评论ID', 400);
      }
      
      await likeModel.likeReview(userId, review_id);
      sendSuccess(res, null, '点赞成功');
    } catch (err) {
      sendError(res, err.message);
    }
  },

  // 取消点赞
  async unlikeReview(req, res) {
    try {
      const { id: userId } = req.user;
      const { review_id } = req.params;
      
      await likeModel.unlikeReview(userId, review_id);
      sendSuccess(res, null, '已取消点赞');
    } catch (err) {
      sendError(res, err.message);
    }
  },

  // 检查是否已点赞
  async checkLike(req, res) {
    try {
      const { id: userId } = req.user;
      const { review_id } = req.params;
      
      const hasLiked = await likeModel.checkLike(userId, review_id);
      sendSuccess(res, { has_liked: hasLiked });
    } catch (err) {
      sendError(res, err.message);
    }
  }
};